package com.xrs.xrseducation.coupon.controller;


import com.xrs.xrseducation.coupon.entity.Coupon;
import com.xrs.xrseducation.coupon.service.ICouponService;
import com.xrs.xrseducation.coupon.service.impl.CouponServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 优惠表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-09-21
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {
    @Autowired
    CouponServiceImpl couponService;

    /*
    * 添加一条优惠卷
    * */
    @RequestMapping("addcoupon")
    public void  addcoupon(Coupon coupon){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(new Date());
        coupon.setAddTime(dateString);
        couponService.save(coupon);
    }


    /*
    * 查询所有优惠卷
    * */
    @RequestMapping("/querycoupon")
    @ResponseBody
    public void querycoupon(Integer pa,Integer limit){
        couponService.list();
    }

    /*
    * 根据id查询
    * */
    @RequestMapping("byidcoupon")
    public void  byidcoupon(Integer couid){
        couponService.getById(couid);
    }

    /*
     * 根据id删除
     * */
    @RequestMapping("deletecoupon")
    public void  deletecoupon(Integer couid){
        couponService.removeById(couid);
    }

    /*
     * 根据id删除
     * */
    @RequestMapping("update")
    public void  deletecoupon(Coupon coupon){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(new Date());
        coupon.setUpdateTime(dateString);
        couponService.updateById(coupon);
    }



}
